#include <bits/stdc++.h>
using namespace std;
int t,n,m,L,V,s,cs,ans,p[100005];
struct score
{
    int d,v,a,be,en;
}car[100005];
bool vis[100005];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--)
    {
        memset(vis,0,sizeof(vis));
        memset(car,0,sizeof(car));
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++)
        {
            cin>>car[i].d>>car[i].v>>car[i].a;
            if(car[i].a==0)
            {
                if(car[i].v>V)
                {
                    car[i].be=car[i].d;
                    car[i].en=L;
                }
                else
                    car[i].be=-1;
            }
            if(car[i].a>0)
            {
                if(car[i].v>V)
                {
                    car[i].be=car[i].d;
                    car[i].en=L;
                }
                if(car[i].v==V)
                {
                    car[i].be=car[i].d+1;
                    car[i].en=L;
                }
                if(car[i].v<V)
                {
                    s=(V*V-car[i].v*car[i].v)/(2*car[i].a);
                    if(car[i].d+s+1<=L)
                    {
                        car[i].be=car[i].d+s+1;
                        car[i].en=L;
                    }
                    else
                        car[i].be=-1;
                }
            }
            if(car[i].a<0)
            {
                if(car[i].v<=V)
                    car[i].be-1;
                if(car[i].v>V)
                {
                    s=(V*V-car[i].v*car[i].v)/(2*car[i].a);
                    if(car[i].d+s<=L)
                    {
                        car[i].be=car[i].d;
                        car[i].en=car[i].d+s;
                    }
                    else
                    {
                        car[i].be=car[i].d;
                        car[i].en=L;
                    }
                }
            }
        }
        for(int i=1;i<=m;i++)
            cin>>p[i];
        int cut1=1000005,cut2=0,last=1,num=0;
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
                if(car[j].be!=-1 && car[j].be<=p[i] && car[j].en>=p[i])
                {
                    cut2=max(cut2,car[j].be);
                    if(!vis[j])
                    {
                        vis[j]=1;
                        cs++;
                    }
                    cut1=min(cut1,car[j].en);
                }
            if(num>=p[i] && i!=1)
            {
                ans++;
                last=i;
            }
            else
                if(cut2<=p[last] && i!=1)
                    ans++;
                else
                    last=i;
            num=cut1;
            cut1=1000005;
            cut2=0;
        }
        cout<<cs<<" "<<ans<<endl;
        cs=0;
        ans=0;
    }
    return 0;
}
